

import 'package:flutter/cupertino.dart';
import 'package:sjx/repository/sjx_api.dart';

import '../../../../repository/model/task_detail_model.dart';
import '../../../../repository/model/task_process_step_model.dart';

class ReceiveTaskProcessViewModel with ChangeNotifier {
  List<TaskProcessStepModel>? _listProcess;
  TaskDetailModel? _taskDetailModel;

  List<TaskProcessStepModel>? get listProcess => _listProcess;
  TaskDetailModel? get taskDetailModel => _taskDetailModel;

  bool get isLoading => _listProcess == null || _taskDetailModel == null;

  // 请求任务订单详情
  Future<void> requestOrderDetail(String orderNo) async {
    try {
      _taskDetailModel = await SJXApi.instance().taskOrderDetail(orderNo);
      notifyListeners();
    } catch (e) {
      print('请求任务详情失败: $e');
    }
  }

  // 请求任务进程
  Future<void> requestOrderProcess(String orderNo) async {
    try {
      _listProcess = await SJXApi.instance().taskOrderProcess(orderNo);
      notifyListeners();
    } catch (e) {
      print('请求任务进程失败: $e');
    }
  }

  // 刷新数据
  Future<void> refreshData(String orderNo) async {
    await requestOrderDetail(orderNo);
    await requestOrderProcess(orderNo);
  }
}